#include "stm32f10x.h"                  // Device header
#include "Delay.h"

void Key_Init(void)
{
    // Reset and clock control APB2 Peripheral Line Clock Commond
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); //1. Peripheral 2. Write Enable
    GPIO_InitTypeDef GPIO_InitStructure; // 通过结构体配置初始化数据
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_11; 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
    GPIO_Init(GPIOB, &GPIO_InitStructure); //1. Peripheral Name 2. 结构体地址
}

uint8_t Key1_In(void)
{
    uint8_t keynum = 0;
    if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == 0)
    {
        Delay_ms(20);
        while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == 0);
        Delay_ms(20);
        keynum = 1;
    }
    return keynum;
}

uint8_t Key2_In(void)
{
    uint8_t keynum = 0;
    if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0) == 0)
    {
        Delay_ms(20);
        while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0) == 0);
        Delay_ms(20);
        keynum = 2;
    }
    return keynum;
}
